﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GMS.BIZ;
using System.Collections;
using System.Data;
using System.Drawing;

namespace Web.Paper
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            if (!((Account)Session["Account"]).RoleCurrent.Equals('t')) Response.Redirect("Default.aspx");
            if (((Teacher)Session["Teacher"]).TeacherName == "")
                Response.Redirect("~/Information/TeaInformation.aspx");
            GridView_GuideStudents = this.FillData_GridView_GuideStudents(GridView_GuideStudents);

            DataSet ds = Defense.GetDefenseList(((Teacher)Session["Teacher"]).TeacherId);
            if (ds.Tables[0].Rows.Count!=0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    ds.Tables[0].Rows[i]["def_tch_1"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_1"].ToString());
                    ds.Tables[0].Rows[i]["def_tch_2"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_2"].ToString());
                    ds.Tables[0].Rows[i]["def_tch_3"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_3"].ToString());
                    ds.Tables[0].Rows[i]["def_tch_4"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_4"].ToString());
                    ds.Tables[0].Rows[i]["def_tch_5"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_5"].ToString());
                    ds.Tables[0].Rows[i]["def_assistant"] = Staff.GetName(ds.Tables[0].Rows[i]["def_assistant"].ToString());
                }
                GridView_DefenseInfo.DataSource = ds;
                GridView_DefenseInfo.DataBind();
            }
            else
                Label_NoDefenseInfo.Text = "未安排答辩场次";
           
        }
        protected void ImageButton_Detail_Click(object sender, ImageClickEventArgs e)
        {
        }
        protected GridView FillData_GridView_GuideStudents(GridView inGridView)
        {
            Teacher myTeacher = (Teacher)Session["Teacher"];
            
            //making dataset
            DataSet ds = new DataSet();
            DataTable tb = new DataTable();
            ds.Tables.Add(tb);
            tb.Columns.Add("学生学号");
            tb.Columns.Add("学生姓名");
            tb.Columns.Add(Resources.Docs.Doc1);
            tb.Columns.Add(Resources.Docs.Doc2);
            tb.Columns.Add(Resources.Docs.Doc3);
            tb.Columns.Add(Resources.Docs.Doc4);
            tb.Columns.Add(Resources.Docs.Doc5);
            tb.Columns.Add(Resources.Docs.Doc6);

            //fill data
            ArrayList arraylist = new ArrayList();
            arraylist = myTeacher.GuideStudents.GetList();
            try
            {
                for (int i = 0; i < arraylist.Count; i++)
                {
                    DataRow dr = tb.NewRow();
                    dr["学生学号"] = arraylist[i].ToString();
                    dr["学生姓名"] = Student.GetName(arraylist[i].ToString());
                    Student newStudent = new Student(arraylist[i].ToString());
                    PaperInfo newPaperInfo = new PaperInfo();
                    newPaperInfo = newStudent.Papers.GetPaperInfo();

                    dr[Resources.Docs.Doc1] = MakingString(newPaperInfo.Doc1status, newStudent.StudentID, 1);
                    dr[Resources.Docs.Doc2] = MakingString(newPaperInfo.Doc2status, newStudent.StudentID, 2);
                    dr[Resources.Docs.Doc3] = MakingString(newPaperInfo.Doc3status, newStudent.StudentID, 3);
                    dr[Resources.Docs.Doc4] = MakingString(newPaperInfo.Doc4status, newStudent.StudentID, 4);
                    dr[Resources.Docs.Doc5] = MakingString(newPaperInfo.Doc5status, newStudent.StudentID, 5);
                    dr[Resources.Docs.Doc6] = MakingString(newPaperInfo.Doc6status, newStudent.StudentID, 6);

                    tb.Rows.Add(dr);
                }
            }
            catch
            {
                Label_noStu.Text = "我没有指导学生";
            }
            inGridView.DataSource = ds;
            inGridView.DataBind();
            return inGridView;
        }

        protected string MakingString(int? status, string studentID, int style)
        {
            //Getting Status
            //If Empty,
            if (status == null) status = 0;
            string str = DocumentStatus.GetName(int.Parse(status.ToString()));

            string colorRGB="";
            switch (status)
            {
                case 0: colorRGB= "F0D1D0"; break;
                case 1: colorRGB = "E8FFD1"; break;
                default: colorRGB = ""; break;
            }

            str = "<a style=\"background-color:#" + colorRGB + "\" href=\"TeaPaperFile.aspx?student=" + studentID + "&style=" + style + "\">" + str;
            str = str + "</a>";

            return str;
        }

      

        protected void GridView_GuideStudents_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView_GuideStudents.PageIndex = e.NewPageIndex;
            GridView_GuideStudents = this.FillData_GridView_GuideStudents(GridView_GuideStudents);

        }

        protected void GridView_DefenseInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView_DefenseInfo.PageIndex = e.NewPageIndex;
            DataSet ds = Defense.GetDefenseList(((Teacher)Session["Teacher"]).TeacherId);
            if (ds.Tables[0].Rows.Count != 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    ds.Tables[0].Rows[i]["def_tch_1"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_1"].ToString());
                    ds.Tables[0].Rows[i]["def_tch_2"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_2"].ToString());
                    ds.Tables[0].Rows[i]["def_tch_3"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_3"].ToString());
                    ds.Tables[0].Rows[i]["def_tch_4"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_4"].ToString());
                    ds.Tables[0].Rows[i]["def_tch_5"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_5"].ToString());
                    ds.Tables[0].Rows[i]["def_assistant"] = Staff.GetName(ds.Tables[0].Rows[i]["def_assistant"].ToString());
                }
                GridView_DefenseInfo.DataSource = ds;
                GridView_DefenseInfo.DataBind();
            }
        }  
    }
}
